/*
 * Copyright 2007. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the GNU Lesser General Public License, Version 2. You
 * can find a copy of the license at:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */
package com.sinai.mshab.client.ui.basic;

import com.google.gwt.user.client.ui.SourcesClickEvents;
import com.sinai.mshab.client.ui.aggregate.Page;
import com.sinai.mshab.client.ui.aggregate.PageContainerPanel;

/**
 * Contains useful information for items that are stored inside of
 * {@link PageContainerPanel}s.
 * 
 * @author Arthur Kalmenson
 */
public class PageContainerPanelItem {

	/**
	 * The index of the item.
	 */
	private int index;

	/**
	 * This items parent <code>PageContainerPanel</code>.
	 */
	private PageContainerPanel parentPanel;

	/**
	 * The component being placed inside the <code>PageContainerPanel</code>.
	 */
	private SourcesClickEvents component;

	/**
	 * The name of this item.
	 */
	private String name;

	/**
	 * Indicates whether this item is {@link Page} level, i.e. it only appears
	 * in the appropriate pages.
	 */
	private boolean pageLevel;

	/**
	 * Creates a new <code>PageContainerPanelItem</code> inside of
	 * <code>panel</code>.
	 * 
	 * @param name
	 *            the name of the widget.
	 * @param widget
	 *            the widget to put inside the panel.
	 * @param panel
	 *            the parent of this item.
	 * @param pageLevel
	 *            whether this item is page level or not.
	 */
	public PageContainerPanelItem(String name, SourcesClickEvents widget,
			PageContainerPanel panel, boolean pageLevel) {
		this.name = name;
		this.index = panel.getWidgetCount();
		parentPanel = panel;
		this.component = widget;
		this.pageLevel = pageLevel;
	}

	/**
	 * Creates a new <code>PageContainerPanelItem</code> inside of
	 * <code>panel</code> at index, index.
	 * 
	 * @param name
	 *            the name of the widget.
	 * @param widget
	 *            the widget to put inside the panel.
	 * @param panel
	 *            the parent of this item.
	 * @param index
	 *            the index where to place it.
	 * @param pageLevel
	 *            whether this item is page level or not.
	 */
	public PageContainerPanelItem(String name, SourcesClickEvents widget,
			PageContainerPanel panel, int index, boolean pageLevel) {
		this.name = name;
		this.index = index;
		parentPanel = panel;
		this.component = widget;
		this.pageLevel = pageLevel;
	}

	/**
	 * Returns the index of this <code>PageContainerPanelItem</code>.
	 * 
	 * @return the index of this <code>PageContainerPanelItem</code>.
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * Returns the parent of this <code>PageContainerPanelItem</code>.
	 * 
	 * @return the parentPanel
	 */
	public PageContainerPanel getParentPanel() {
		return parentPanel;
	}

	/**
	 * Returns this <code>PageContainerPanelItem</code>'s component.
	 * 
	 * @return this <code>PageContainerPanelItem</code>'s component.
	 */
	public SourcesClickEvents getComponent() {
		return component;
	}

	/**
	 * Sets this <code>PageContainerPanelItem</code>'s component to
	 * <code>widget</code>.
	 * 
	 * @param widget
	 *            the new component.
	 */
	public void setComponent(SourcesClickEvents widget) {
		this.component = widget;
	}

	/**
	 * Returns the name of this <code>PageContainerPanelItem</code>.
	 * 
	 * @return the name of this <code>PageContainerPanelItem</code>.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns whether this item is Page level. This means that this item should
	 * only appear on a specific page.
	 * 
	 * @return whether this item is Page level.
	 */
	public boolean isPageLevel() {
		return pageLevel;
	}

	/**
	 * Sets whether this item is Page level. This means that this item should
	 * only appear on a specific page.
	 * 
	 * @param pageLevel
	 *            the new value.
	 */
	public void setPageLevel(boolean pageLevel) {
		this.pageLevel = pageLevel;
	}
}
